Skip to content

Conversation

@iseeberg79
Copy link
Contributor

@iseeberg79 iseeberg79 commented Dec 8, 2025

This PR enables auto-filling of device parameters in the configuration UI by reading actual values from the device.

Adds HTTP service endpoint /api/modbus/params for reading device parameters based on template definitions without creating a full device instance.

Features (fixes #25857):

  • Dynamic register reading using template configurations
  • Automatic scaling and type conversion

Usage examples:

  • ModbusTCP
  - name: capacity
    type: int
    unit: kWh
    advanced: true
    usages: ["battery"]
    service: modbus/params?uri={host}:{port}&id={id}&address=1068&type=holding&encoding=float32s&scale=0.001&resulttype=int
  • rs485serial
  - name: capacity
    type: float
    unit: kWh
    advanced: true
    usages: ["battery"]
    service: modbus/params?device={device}&baudrate={baudrate}&comset={comset}&id={id}&address=1068&type=holding&encoding=float32s&scale=0.001

recently updated to reduce to:

- name: maxacpower
  service: modbus/read?address=1069&type=holding&encoding=float32s&scale=0.001&{modbus}

TODO:

  • refactor datalist handling (less duplicate code) @naltatis

@andig andig added enhancement New feature or request needs documentation Triggers issue creation in evcc-io/docs labels Dec 8, 2025
@andig
Copy link
Member

andig commented Dec 8, 2025

Das ist grausig viel Logik. Warum muss der modbus Service etwas vin templates wissen? Die sollten ihm egal sein! Spannend ist allerdings die Modbus Config. Dafür hatte ich keine gute Idee :/

@iseeberg79
Copy link
Contributor Author

iseeberg79 commented Dec 8, 2025

Das ist grausig viel Logik. Warum muss der modbus Service etwas vin templates wissen? Die sollten ihm egal sein! Spannend ist allerdings die Modbus Config. Dafür hatte ich keine gute Idee :/

Die zu ermittelnden Register lädt er aus dem Template zur Laufzeit, nachdem die Modbus-Konfiguration verfügbar ist. Dafür der Name des Templates. Man könnte das Laden des Template ggf. überflüssig machen: statt properties, mehr URL Parameter. Auch deinen Hinweis mit dem modbus-Plugin.. - schau' ich mir an.

Die UI Integration ist etwas schwierig, wg. der Einschränkung mit den dataLists und der Positionierung des clear-Feldes bei Feldern mit Einheit. Das ist noch unschön, überlappt aber so aktuell nicht mehr - die Ausrichtung passt aktuell nicht.
Ich stell' das mal hinten an erstmal... - ich hatte zuerst die Werte direkt in die Felder geschrieben, wenn initial - das widerspricht aber der aktuellen Integration/Tests aus demo-service. Die Dropdown's sind schon ganz charmant...

image

@andig
Copy link
Member

andig commented Dec 9, 2025

Die zu ermittelnden Register lädt er aus dem Template zur Laufzeit,

Die gehören in den Serviceaufruf. HA zeigt wie's geht:

service: homeassistant/entities?uri={uri}&domain=sensor

Die uri wird dynamisch vom UI da rein gebastelt. Ich weiss nur nicht ob/wie wir das für Modbus zum Leben erwecken können.

/cc @naltatis

@iseeberg79
Copy link
Contributor Author

iseeberg79 commented Dec 9, 2025

Ich bin einen Entwurf weiter, klappt soweit auch mit URL Parametern, ist übersichtlicher. Ein Update heute Abend!

Problematisch ist die Parallelität der Browseranfragen und Wiederverwendung des Modbus-Plugins, theoretisch läuft es.

Praktisch blockierte da gerade etwas, was einen weiteren echten Gerätetest braucht.

Der aktuelle Ansatz ist unnötig aufwändig, läuft aber.

@andig
Copy link
Member

andig commented Dec 9, 2025

Checks gerne ein, ich kann auch testen.

@iseeberg79
Copy link
Contributor Author

Checks gerne ein, ich kann auch testen.

jetzt aber...

Copy link
Member

@naltatis naltatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added e2e tests, found a couple of bugs around how we handled modbus default values. This should all work fine now.

@iseeberg79
Copy link
Contributor Author

iseeberg79 commented Jan 3, 2026

Your changes are working fine, thank you!

Copy link
Contributor Author

@iseeberg79 iseeberg79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about the failing test, it's to decide how to handle empty strings?

@iseeberg79
Copy link
Contributor Author

iseeberg79 commented Jan 3, 2026

currently I have no clue how to handle this per template using recently added battery-presets, but to remove those if a parameter uses service?

@naltatis
Copy link
Member

naltatis commented Jan 6, 2026

@andig anything to add? or should we merge?

@andig
Copy link
Member

andig commented Jan 6, 2026

Nice. Lets open another TODO for documenting the template author service somewhere?

@naltatis
Copy link
Member

TODO for documenting the template author service somewhere?

Updated the templates/README.md. Added auth, service and corrected a lot of other outdated info.

@naltatis naltatis enabled auto-merge (squash) January 13, 2026 12:12
@naltatis naltatis merged commit b02f3d9 into evcc-io:master Jan 13, 2026
6 checks passed
@FrankvdAa
Copy link
Contributor

FrankvdAa commented Jan 16, 2026

Hi, I'm working on adding Atmoce grid/pv/battery system as device and would like to use this modbus/read to get the battery capacity through modbus.

The params-section is configured as follows:

params:
  - name: usage
    choice: ["grid", "pv", "battery"]
  - name: modbus
    choice: ["rs485", "tcpip"]
    baudrate: 9600
    id: 1
  - name: minsoc
    advanced: true
    default: 20
  - name: maxsoc
    advanced: true
    default: 80
  - name: maxacpower
    advanced: true
  - name: capacity
    advanced: false
    service: modbus/read?address=60031&type=holding&encoding=uint32&scale=0.001&resulttype=int&{modbus}

In the GUI I have set correct IP and port:
Modbus-settings

However, it's failing with a HTTP code 500 and I can see that the port number is truncated; it says ...:50 instead of ...:502. When I manually call the API endpoint with the correct port number, I get the correct capacity.

HTTP-error-500

Am I doing something wrong here?

Edit: this is on latest version: evcc version 5ca34f06 (5ca34f06)

@andig
Copy link
Member

andig commented Jan 16, 2026

Maybe #26726?

@naltatis
Copy link
Member

naltatis commented Jan 16, 2026

Maybe #26726?

My guess is, that this is a request that was triggered while typing 5 0 2. The service endpoint is expected to always return a proper 200 result. If it can't find values (wrong port) it should just return an empty list response, not an error message, since we dont have a spot to show errors in this case.
\cc @iseeberg79

Related info: In #26698 I'm switching from input based field updates (every keypress) to change based updates (on blur). The change in that PR is for other reasons, but will also eliminate these in-between checks.

@iseeberg79
Copy link
Contributor Author

iseeberg79 commented Jan 16, 2026

while typing 5 0 2

good catch. There is a short delay (500ms debounce) for the input field before the service is called for already "complete" parameter sets. Have seen it in the browsers development console for example on hostnames but never realized the error messages, yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs documentation Triggers issue creation in evcc-io/docs prio Priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support reading configuration values from devices

4 participants